package main

import (
	"fmt"
	"sort"
)

func main() {
	//map的排序
	map1 := make(map[int]int, 10)
	map1[10] = 100
	map1[1] = 23
	map1[4] = 58
	map1[8] = 98
	map1[13] = 31
	map1[55] = 92
	map1[32] = 123
	map1[78] = 93

	fmt.Println(map1)

	/*
		1 23
		4 58
		10 100
		8 98
	*/
	//for key, value := range map1 {
	//	fmt.Println(key, value)
	//}

	//按照key升序输出map的key=>value
	//1、把map的key放在切片里面
	var keys []int
	for key, _ := range map1 {
		//fmt.Println(key, value)
		keys = append(keys, key) //用切片存储map的所有key
	}

	//排序切片
	sort.Ints(keys)
	fmt.Println(keys)

	//循环遍历k，输出map的值
	for _, key := range keys {
		fmt.Printf("%v-%v \n", key, map1[key])
	}
}
